<?php

set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/php/account/private/lib');

spl_autoload_register(
    function ($className)
    {
        $className = str_replace("_", "\\", $className);
        $className = ltrim($className, '\\');
        $fileName = '';
        $namespace = '';
        if ($lastNsPos = strripos($className, '\\'))
        {
            $namespace = substr($className, 0, $lastNsPos);
            $className = substr($className, $lastNsPos + 1);
            $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
        }
        $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

        require $fileName;
    }
);

require_once("storm/DistributedRPC.php");
use Thrift\Transport\TSocket;
use Thrift\Transport\TFramedTransport;
use Thrift\Protocol\TBinaryProtocol;

$random = mt_rand(1,9);
$random2 = mt_rand(1,9);
$random3 = mt_rand(1,9);

$socket = new TSocket("ec2-54-249-168-222.ap-northeast-1.compute.amazonaws.com", 3772);
$socket->setSendTimeout(30000);
$socket->setRecvTimeout(30000);

$conn = new TFramedTransport($socket);
$client = new DistributedRPCClient(new TBinaryProtocol($conn));
$conn->open();

$result = $client->execute("account", "{\"username\":\"test\",\"payment\":10}");

$str =<<< _EOF_
<html>
<head>
</head>
<body>
<center>
スロットゲーム(1回10円)
<br>
<br>
<b>結果 : {$random}{$random2}{$random3}</b>
<br>
<!-- <b>結果 : {$result}</b> -->
<br>
<a href="./game.php">もう一回</a>
<br>
<br>
<a href="./hist.php">利用履歴</a>
</center>
</body>
</html>

_EOF_;

print $str;
